home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2007 December / PCWKCD1207B.iso / Blogowanie poza sfera / Scribefire-1.4.2 / scribefire-1.4.2-fx+fl.xpi / chrome / content / overlay.js < prev    next >
Encoding:
JavaScript  |  2007-07-24  |  13.4 KB  |  320 lines

  1. /* ===================================================================
  2. // All code unless otherwise posted is licensed under the GPL as specified in license.txt
  3. // ===================================================================*/
  4. var gPerFormancingFirstStart = false;
  5. var gPerformancingVersion = "1.4.2";
  6. var gPerformancingVersionUA = "1.4.2";
  7. var gPFFBlogThisText = [false];
  8.  
  9. function performancing() {
  10.     //Prefs System | http://www.xulplanet.com/references/xpcomref/comps/c_preferencesservice1.html
  11.     // usage: this.prefs.getBoolPref('somevalue') which in prefs will be performancing.somevalue;
  12.     this.prefsService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
  13.     this.prefs = this.prefsService.getBranch("performancing.");// Get the "performancing." branch
  14.     
  15.     //Pref obvserver, so any change to a pref will cause a live change. | http://www.xulplanet.com/references/xpcomref/ifaces/nsIPrefBranchInternal.html
  16.     //This will call the 'observe' function below everytime a pref changes.
  17.     this.pbiPref = this.prefs.QueryInterface(Components.interfaces.nsIPrefBranchInternal);
  18.     this.pbiPref.addObserver("", this, false); //Pref Change Observer
  19.     
  20.     //Get Elements
  21.     //We get them here, once, to improve performance
  22.     this.performancing_statusbar_panel = document.getElementById("performancing-statusbar-panel");
  23.     this.performancing_sb_button = document.getElementById("performancing-sb-button");
  24.     
  25.     //Localization Strings
  26.     // All ours strings are localizable, strings used in javascript are found here
  27.     this.stringBundle = document.getElementById("performancingstrings");
  28.     
  29.     //Observers
  30.     this._observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
  31.     //this._observerService.addObserver(this, PERFORMANCING_STATE_CHANGED_TOPIC, false);
  32.     /*this._observerService.notifyObservers(null, 
  33.                                                 PERFORMANCING_STATE_CHANGED_TOPIC, 
  34.                                                 PERFORMANCING_STATE_LOADBLOGS);
  35.     */
  36.     
  37. }
  38.  
  39. //This is where all the good stuff goes!
  40. performancing.prototype = {
  41.   
  42.   //First thing we do is load prefs.
  43.   init: function() {
  44.     //Get the pref and set defaults
  45.     this.getPrefs();
  46.     this.loadPositionPrefs();
  47.     performancingSetPerFormancingPosition();
  48.     this.logError('Done Loading PerFormancing ')
  49.     //window.setTimeout('gperformancing.silentOpenBottomBar()', 8000, true);
  50.     this.showHideCM();
  51.     
  52.     var appcontent = window.document.getElementById("appcontent");
  53.     if (appcontent) {
  54.         if (!appcontent.performancing) {
  55.             appcontent.performancing = true;
  56.             appcontent.addEventListener("DOMContentLoaded", gperformancing.onPageDomLoad, false);
  57.         }
  58.     }
  59.     
  60.     //gperformancing.openBottomBar()
  61.   },
  62.   
  63.   getLocaleString: function(strName, formattingValues) {
  64.         var str = null;
  65.         try {
  66.             var strbundle = document.getElementById("performancingstrings");
  67.             var strbundleFallback = document.getElementById("performancingstrings-fallback");
  68.             if (formattingValues === undefined) {
  69.                 try {
  70.                     str = strbundle.getString(strName);
  71.                 } catch(e) {
  72.                     str = strbundleFallback.getString(strName);
  73.                 }
  74.             } else {
  75.                 try {
  76.                     str = strbundle.getFormattedString(strName, formattingValues);
  77.                 } catch(e) {
  78.                     str = strbundleFallback.getFormattedString(strName, formattingValues);
  79.                 }
  80.             }
  81.         } catch (err) {
  82.             //this.printLine("Couldn't get string: " + strName);
  83.         }
  84.         return str;
  85.     },
  86.   
  87.   //Get prefs and set UI values 
  88.   getPrefs: function() {
  89.           this.performancing_sb_button.setAttribute('changed', this.prefs.getBoolPref('changed') );
  90.   },
  91.   
  92.   launchSettings: function() {
  93.           window.openDialog('chrome://performancing/content/settings.xul', '_blank', 'chrome,centerscreen,resizable=no,dependent=yes')
  94.   },
  95.   
  96.   launchWindow: function(xulDoc) {
  97.           window.open(xulDoc, '_blank', 'chrome,centerscreen,resizable=yes,titlebar=yes,dependent=no')
  98.   },
  99.   
  100.   launchWindowInTab: function(xulDoc) {
  101.           //window.open(xulDoc, '_blank', 'chrome,centerscreen,resizable=yes,titlebar=yes,dependent=no')
  102.           var editorInTab = gBrowser.addTab(xulDoc);
  103.           getBrowser().selectedTab = editorInTab;
  104.   },
  105.   
  106.   isOpen: function() {
  107.       var theSRC = document.getElementById("perFormancingMidasFrame").getAttribute("src");
  108.       if(theSRC == "chrome://performancing/content/editor.xul"){
  109.           return true;
  110.       }else{
  111.           return false
  112.       }
  113.   },
  114.   
  115.   openBottomBar: function(doOpen) {
  116.           var bottomBar = document.getElementById("performancing-outerbox");
  117.           var performancingSplinter = document.getElementById("performancingSplit");
  118.           //document.getElementById("performancing-topeditor-bar").setAttribute('collapsed', true );
  119.           //document.getElementById("performancing-navbar").setAttribute('collapsed', true );
  120.           //performancing-navbuttons-small
  121.           var isOnBottom = this.prefs.getBoolPref("display.onbottom");
  122.           var isOnRight = false; //Add a pref here
  123.           if(isOnBottom && !gPerFormancingFirstStart && !isOnRight){
  124.               var theContent = document.getElementById("appcontent");
  125.               theContent.appendChild(performancingSplinter);
  126.               theContent.appendChild(bottomBar);
  127.               gPerFormancingFirstStart = true;
  128.               //bottomBar.setAttribute('insertafter', 'content' );
  129.               //performancingSplinter.setAttribute('insertafter', 'content' );
  130.           }else if(isOnRight){ // Prototype Right Side PFF
  131.               var theGrippy = document.getElementById("performancing-grippy");
  132.               theGrippy.setAttribute("style", "");
  133.               bottomBar.setAttribute("width", "200px");
  134.               var theContent = document.getElementById("browser");
  135.               theContent.appendChild(performancingSplinter);
  136.               theContent.appendChild(bottomBar);
  137.               gPerFormancingFirstStart = true;
  138.           }
  139.           
  140.           if(doOpen){
  141.               bottomBar.setAttribute('collapsed', false );
  142.               performancingSplinter.setAttribute('collapsed', false );
  143.           }else{
  144.               bottomBar.setAttribute('collapsed', !bottomBar.collapsed );
  145.               performancingSplinter.setAttribute('collapsed', !performancingSplinter.collapsed );
  146.           }
  147.           document.getElementById("perFormancingMidasFrame").setAttribute("src", "chrome://performancing/content/editor.xul");
  148.           //document.getElementById("performancing-editor-tab").setAttribute('class', 'performancing-navbuttons-small' );
  149.           //document.getElementById("performancing-pageinfo-tab").setAttribute('class', 'performancing-navbuttons-small' );
  150.           //document.getElementById("performancing-notes-tab").setAttribute('class', 'performancing-navbuttons-small' );
  151.           //To access inside of the iframe: document.getElementById("perFormancingMidasFrame").contentDocument
  152.           // i.e: document.getElementById("perFormancingMidasFrame").contentDocument.getElementById("messagesource").value
  153.   },
  154.   
  155.   silentOpenBottomBar: function(){
  156.       var bottomBar = document.getElementById("performancing-outerbox");
  157.       var performancingSplinter = document.getElementById("performancingSplit");
  158.       var isOnBottom = this.prefs.getBoolPref("display.onbottom");
  159.       if(isOnBottom && !gPerFormancingFirstStart){
  160.               var theContent = document.getElementById("appcontent");
  161.               theContent.appendChild(performancingSplinter);
  162.               theContent.appendChild(bottomBar);
  163.               gPerFormancingFirstStart = true;
  164.               //bottomBar.setAttribute('insertafter', 'content' );
  165.               //performancingSplinter.setAttribute('insertafter', 'content' );
  166.               //alert("Dude");
  167.       }
  168.       document.getElementById("perFormancingMidasFrame").setAttribute("src", "chrome://performancing/content/editor.xul");
  169.   },
  170.   
  171.   //performancing-technorati-tab
  172.   onPageDomLoad: function() {
  173.     //Get the pref and set defaults
  174.     try{
  175.         var myIframeWindow = document.getElementById('perFormancingMidasFrame').contentWindow;
  176.         var myIframeWindowDoc = document.getElementById('perFormancingMidasFrame').contentDocument;
  177.         if( myIframeWindowDoc.getElementById('performancing-technorati-tab').getAttribute('selected') == 'true' ){
  178.             myIframeWindow.setTimeout("performancingUI.getPageInfo('technorati')", 1000, true);
  179.         }else if( myIframeWindowDoc.getElementById('performancing-delicious-tab').getAttribute('selected') == 'true' ){
  180.             myIframeWindow.setTimeout("performancingUI.getPageInfo('delicious')", 1000, true);
  181.         }
  182.     }catch(e){
  183.         //foo
  184.     }
  185.   },
  186.   
  187.   someAction: function() {
  188.     //Get the pref and set defaults
  189.     var alertText = this.stringBundle.getString("performancing.someaction");
  190.     alert(alertText);
  191.   },
  192.   
  193.   //Show or hide the Context Menu depending on pref
  194.   showHideCM: function() {
  195.     try{ //Do 'try' in odd case where XUL hasn't initialized yet
  196.         if(this.prefs.getBoolPref('display.hideContextMenu')){ //
  197.             document.getElementById("context-performancing-sep").hidden = true;
  198.             document.getElementById("context-performancing").hidden = true;
  199.         }else{
  200.             document.getElementById("context-performancing-sep").hidden = false;
  201.             document.getElementById("context-performancing").hidden = false;
  202.         }
  203.     }catch(e){
  204.         
  205.     }
  206.   },
  207.   
  208.   /*Observe function, currently only observes changes to preferences*/
  209.   observe: function(aSubject, aTopic, aData) {
  210.         if(aTopic == "nsPref:changed"){//If Pref changes (performancing.*), do something
  211.              this.getPrefs();//Make our changes live
  212.         }else if(aTopic == PERFORMANCING_STATE_CHANGED_TOPIC){
  213.             //this.reloadBlogs();
  214.         }
  215.         
  216.     },
  217.     
  218.   onMenuItemCommand: function() {
  219.        var alertText = this.stringBundle.getString("performancing.someaction");
  220.        alert(alertText);
  221.   },
  222.   
  223.   reloadBlogs: function() {
  224.        var alertText = this.stringBundle.getString("performancing.someaction");
  225.        alert(alertText);
  226.   },
  227.   
  228.   logError: function(amsg) {
  229.        dump(amsg + "\n" );
  230.   },
  231.   
  232.   savePositionPrefs: function( ) {
  233.      // Foo
  234.          try {
  235.            this.prefs.setCharPref("position.parent_element_id", gPerFormancingParentElementID);
  236.            this.makeToolbarItem(gPerFormancingParentElementID);
  237.          } 
  238.          catch (err) {
  239.            this.printLog("\nSetting preference for parent_element_id failed: " + err + "\n");
  240.          }
  241.       
  242.          try {
  243.            this.prefs.setCharPref("position.insert_before_element_id", gPerFormancingInsertBeforeElementId);
  244.          } 
  245.          catch (err) {
  246.            this.printLog("\nSetting preference for insert_before_element_id failed: " + err + "\n");
  247.          }
  248.       
  249.          try {
  250.            this.prefs.setCharPref("position.insert_after_element_id", gPerFormancingInsertAfterElementId);
  251.          } 
  252.          catch (err) {
  253.            this.printLog("\nSetting preference for insert_after_element_id failed: " + err + "\n");
  254.          }
  255.     },
  256.     
  257.     makeToolbarItem: function( aElement ) {
  258.      var pffStatusBar = document.getElementById("performancing-sb-button");
  259.      if(aElement == "nav-bar" || aElement == "mail-bar" ){
  260.          pffStatusBar.setAttribute("label", "ScribeFire");
  261.          pffStatusBar.setAttribute("class", "performancing-statusbar-button toolbarbutton-1");
  262.       }else{
  263.          pffStatusBar.setAttribute("label", "");
  264.          pffStatusBar.setAttribute("class", "performancing-statusbar-button");
  265.       }
  266.     },
  267.     
  268.     loadPositionPrefs: function() {
  269.          try {
  270.            gPerFormancingParentElementID = this.prefs.getCharPref("position.parent_element_id");
  271.            this.makeToolbarItem(gPerFormancingParentElementID);
  272.          } 
  273.          catch (err) {
  274.            gPerFormancingParentElementID = '';
  275.          }
  276.       
  277.          try {
  278.            gPerFormancingInsertBeforeElementId = this.prefs.getCharPref("position.insert_before_element_id");
  279.          } 
  280.          catch (err) {
  281.            gPerFormancingInsertBeforeElementId = '';
  282.          }
  283.       
  284.          try {
  285.            gPerFormancingInsertAfterElementId = this.prefs.getCharPref("position.insert_after_element_id");
  286.          } 
  287.          catch (err) {
  288.            gPerFormancingInsertAfterElementId = '';
  289.          }
  290.     }
  291.   
  292. }
  293.  
  294. //Initialize our object.
  295. var gperformancing = null;
  296. function onPerFormancingLoad() {
  297.     try {
  298.         gperformancing = new performancing();
  299.         gperformancing.logError('Loading PerFormancing'); //Debuging window, see kb.mozilla.org on how to set up firefox for debug windows.
  300.     } catch(e) { alert(e); }
  301.     gperformancing.init();//Load Prefs
  302. }
  303.  
  304.  
  305. //STATUSBUTTON POSITION
  306. // ***Declare Globar Variables for Drag and Drop***
  307. var gPerFormancingCurrentDropTarget = null;
  308. // the id of the DOM element to position PerFormancing at:
  309. var gPerFormancingParentElementID = "";
  310.  
  311. // the id of the DOM element to insert PerFormancing before
  312. // if equals to the parent ID, insert as the last child:
  313. var gPerFormancingInsertBeforeElementId = "";
  314. // if the insert before fails, try inserting after this one:
  315. var gPerFormancingInsertAfterElementId = "";
  316.  
  317.  
  318. //Make sure we load on start-up of browser.
  319. window.addEventListener('load', onPerFormancingLoad, false); 
  320.